package com.example.back_code.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.back_code.entity.po.VerticalProject;
import com.example.back_code.mapper.VerticalProjectMapper;
import com.example.back_code.service.VerticalProjectService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class VerticalProjectServiceImpl extends ServiceImpl<VerticalProjectMapper, VerticalProject> implements VerticalProjectService {
    @Override
    public boolean auditProject(Long id, Integer status, String rejectReason) {
        VerticalProject project = getById(id);
        if (project == null) return false;
        project.setStatus(status);
        if (status != null && status == 2) {
            project.setRejectReason(rejectReason);
        }
        return updateById(project);
    }

    @Override
    public List<VerticalProject> filterProjects(String paperName, String startDate, String endDate, Integer status) {
        QueryWrapper<VerticalProject> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(paperName)) {
            wrapper.like("paper_name", paperName);
        }
        if (StringUtils.hasText(startDate)) {
            wrapper.ge("publish_date", startDate);
        }
        if (StringUtils.hasText(endDate)) {
            wrapper.le("publish_date", endDate);
        }
        if (status != null) {
            wrapper.eq("status", status);
        }
        return list(wrapper);
    }
}
